<template>
  <div class="map-type" :style="{'inset': location}">
    <div class="po">
      <div class="item" :class="{ 'on': mapStyle === 1 }" @click="changeMapStyle(1)">
        <img src="@/assets/image/map_normal.jpg" alt=""/>
        <span>常规地图</span>
      </div>
      <div class="item" :class="{ 'on': mapStyle === 2 }" @click="changeMapStyle(2)">
        <img src="@/assets/image/map_star.jpg" alt=""/>
        <span>卫星地图</span>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "mapType",
  data() {
    return {
      mapStyle: -1, //地图主题
    };
  },
  props: {
    location:{
      type: String,
      default: 'auto 50px 10px auto'
    },
    mapType:{
      type: Number,
      default: 1,
    },
    mapMap:{
      type:Object,
      required: true,
    }
  },
  watch: {
    mapType: {
      handler(val) {
        this.mapStyle = val;
        $('.map-type .po').css({
          left: -84 * (val - 1) + 'px'
        });
      },
      immediate: true,
    },
  },
  mounted() {
    console.log(this.mapType)
    this.mapStyle = this.mapType;
    $('.map-type .po').css({
      left: -84 * (this.mapType - 1) + 'px'
    });

  },
  methods:{
    changeMapStyle(style){
      if (this.mapStyle === style) {
        return false;
      }
      if (this.mapStyle === 1 && style === 2) {
        this.mapMap.changeTile('satellite');  //卫星图切换为交通地图
      } else if (this.mapStyle === 2 && style === 1) {
        this.mapMap.changeTile('vector');  //交通地图切换为卫星图
      } else {
        console.log('解决sonar问题');
      }
      this.mapStyle = style;
      $('.map-type .po').css({
        left: -84 * (style - 1) + 'px'
      });
    },
  }
}
</script>


<style scoped lang="scss">
.map-type {
  position: absolute;
  font-size: 12px;
  overflow: hidden;
  display: block;
  transition: width 0.3s;
  z-index: 9;
  width: 88px;
  height: 68px;
  background: #FFFFFF;
  //box-shadow: 0 2px 6px 0 rgba(161, 176, 195, 0.7);
  box-shadow: 0 2px 5px 0 rgba(0, 0,0,0.15);
  opacity: 1;
  border-radius: 4px;
  padding: 2px;
  right: 10px;
  bottom: 10px;
}

.map-type .po {
  height: 100%;
  width: 172px;
  position: absolute;
  top: 0;
  left: 0;
  transition: left 0.3s;
  padding: 4px 0;
}

.map-type:hover {
  width: 172px;
}

.map-type:hover .po {
  left: 0 !important;
}

.map-type .item {
  float: left;
  width: 80px;
  height: 60px;
  margin-left: 4px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  border: none !important;
  border-radius: 0 0 4px 4px;
}

.map-type .item img {
  display: block;
  width: 100%;
  height: 100%;
}

.map-type .item span {
  display: block;
  width: 100%;
  height: 20px;
  line-height: 20px;
  text-align: center;
  font-size: 12px;
  color: #333;
  background: #fff;
  position: absolute;
  left: 0;
  bottom: 0;
}

.map-type .item:hover span {
  color: #fff;
  background: #1373E6;
  opacity: 0.8;
}

.map-type .item.on {
  border-color: #00a8ff;
  border-radius: 0 0 4px 4px;
}

.map-type .item.on span {
  color: #fff;
  background: #1373E6;
  opacity: 0.8;
  border-radius: 0 0 4px 4px;
}
</style>
